.class public Lcom/sponsorpay/sdk/android/utils/UserId;
.super Ljava/lang/Object;
.source "UserId.java"


# static fields
.field public static final STATE_GENERATED_USERID_KEY:Ljava/lang/String; = "STATE_GENERATED_USERID_KEY"


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 17
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method private static generateUserId(Lcom/sponsorpay/sdk/android/utils/HostInfo;)Ljava/lang/String;
    .locals 7
    .parameter "hostInfo"

    .prologue
    .line 67
    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    .line 69
    .local v2, builder:Ljava/lang/StringBuilder;
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/utils/HostInfo;->getUDID()Ljava/lang/String;

    move-result-object v5

    .line 70
    .local v5, telephonyDeviceId:Ljava/lang/String;
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/utils/HostInfo;->getAndroidId()Ljava/lang/String;

    move-result-object v0

    .line 71
    .local v0, androidId:Ljava/lang/String;
    invoke-virtual {p0}, Lcom/sponsorpay/sdk/android/utils/HostInfo;->getHardwareSerialNumber()Ljava/lang/String;

    move-result-object v4

    .line 73
    .local v4, hardwareSerialNumber:Ljava/lang/String;
    invoke-static {v5}, Lcom/sponsorpay/sdk/android/utils/UserId;->isValidId(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_0

    .line 74
    invoke-virtual {v2, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    .line 76
    :cond_0
    invoke-static {v0}, Lcom/sponsorpay/sdk/android/utils/UserId;->isValidAndroidId(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_1

    .line 77
    invoke-virtual {v2, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    .line 79
    :cond_1
    invoke-static {v4}, Lcom/sponsorpay/sdk/android/utils/UserId;->isValidId(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_2

    .line 80
    invoke-virtual {v2, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    .line 83
    :cond_2
    invoke-virtual {v2}, Ljava/lang/StringBuilder;->length()I

    move-result v6

    if-nez v6, :cond_3

    .line 84
    invoke-static {}, Ljava/util/UUID;->randomUUID()Ljava/util/UUID;

    move-result-object v6

    invoke-virtual {v2, v6}, Ljava/lang/StringBuilder;->append(Ljava/lang/Object;)Ljava/lang/StringBuilder;

    .line 87
    :cond_3
    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    .line 88
    .local v1, baseText:Ljava/lang/String;
    invoke-static {v1}, Lcom/sponsorpay/sdk/android/utils/SignatureTools;->generateSHA1ForString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v3

    .line 90
    .local v3, generatedId:Ljava/lang/String;
    if-eqz v3, :cond_4

    const-string v6, "nosha1"

    invoke-virtual {v3, v6}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v6

    if-eqz v6, :cond_5

    .line 91
    :cond_4
    move-object v3, v1

    .line 94
    :cond_5
    return-object v3
.end method

.method public static declared-synchronized getAutoGenerated(Landroid/content/Context;Lcom/sponsorpay/sdk/android/utils/HostInfo;)Ljava/lang/String;
    .locals 6
    .parameter "context"
    .parameter "hostInfo"

    .prologue
    .line 22
    const-class v4, Lcom/sponsorpay/sdk/android/utils/UserId;

    monitor-enter v4

    .line 23
    :try_start_0
    const-string v3, "SponsorPayPublisherState"

    const/4 v5, 0x0

    .line 22
    invoke-virtual {p0, v3, v5}, Landroid/content/Context;->getSharedPreferences(Ljava/lang/String;I)Landroid/content/SharedPreferences;

    move-result-object v0

    .line 25
    .local v0, state:Landroid/content/SharedPreferences;
    const-string v3, "STATE_GENERATED_USERID_KEY"

    const/4 v5, 0x0

    invoke-interface {v0, v3, v5}, Landroid/content/SharedPreferences;->getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v2

    .line 27
    .local v2, userIdValue:Ljava/lang/String;
    if-nez v2, :cond_0

    .line 29
    invoke-static {p1}, Lcom/sponsorpay/sdk/android/utils/UserId;->generateUserId(Lcom/sponsorpay/sdk/android/utils/HostInfo;)Ljava/lang/String;

    move-result-object v2

    .line 31
    invoke-interface {v0}, Landroid/content/SharedPreferences;->edit()Landroid/content/SharedPreferences$Editor;

    move-result-object v1

    .line 32
    .local v1, stateEditor:Landroid/content/SharedPreferences$Editor;
    const-string v3, "STATE_GENERATED_USERID_KEY"

    invoke-interface {v1, v3, v2}, Landroid/content/SharedPreferences$Editor;->putString(Ljava/lang/String;Ljava/lang/String;)Landroid/content/SharedPreferences$Editor;

    .line 33
    invoke-interface {v1}, Landroid/content/SharedPreferences$Editor;->commit()Z
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 36
    .end local v1           #stateEditor:Landroid/content/SharedPreferences$Editor;
    :cond_0
    monitor-exit v4

    return-object v2

    .line 22
    .end local v0           #state:Landroid/content/SharedPreferences;
    .end local v2           #userIdValue:Ljava/lang/String;
    :catchall_0
    move-exception v3

    monitor-exit v4

    throw v3
.end method

.method private static isValidAndroidId(Ljava/lang/String;)Z
    .locals 1
    .parameter "androidId"

    .prologue
    .line 41
    invoke-static {p0}, Lcom/sponsorpay/sdk/android/utils/UserId;->isValidId(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    const-string v0, "9774d56d682e549c"

    invoke-virtual {p0, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_1

    .line 42
    :cond_0
    const/4 v0, 0x0

    .line 45
    :goto_0
    return v0

    :cond_1
    const/4 v0, 0x1

    goto :goto_0
.end method

.method private static isValidId(Ljava/lang/String;)Z
    .locals 3
    .parameter "id"

    .prologue
    const/4 v1, 0x0

    .line 51
    invoke-static {p0}, Lcom/sponsorpay/sdk/android/utils/StringUtils;->nullOrEmpty(Ljava/lang/String;)Z

    move-result v2

    if-eqz v2, :cond_1

    .line 63
    :cond_0
    :goto_0
    return v1

    .line 56
    :cond_1
    const/4 v0, 0x0

    .line 58
    .local v0, androidIdAsInteger:Ljava/lang/Integer;
    :try_start_0
    invoke-static {p0}, Ljava/lang/Integer;->parseInt(Ljava/lang/String;)I

    move-result v2

    invoke-static {v2}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;
    :try_end_0
    .catch Ljava/lang/NumberFormatException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v0

    .line 63
    :goto_1
    if-eqz v0, :cond_2

    invoke-virtual {v0}, Ljava/lang/Integer;->intValue()I

    move-result v2

    if-eqz v2, :cond_0

    :cond_2
    const/4 v1, 0x1

    goto :goto_0

    .line 59
    :catch_0
    move-exception v2

    goto :goto_1
.end method
